package com.tsmti.system.entity;

import com.tsmti.core.common.entity.BaseDataEntity;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * @Package：com.tsmti.system.entity
 * @Class：Directory
 * @Description： 字典实体类
 * @Author：zcw
 * @Date：Created in 2018/5/16 15:51
 * @Company:
 * @Version：
 * @Modified By:
 */
@Entity
@Table(name = "pims_dictionary")
@DynamicUpdate
@DynamicInsert
@Where(clause = "delFlag = 0")
public class DataDictionary extends BaseDataEntity<Long> {
    private static final long serialVersionUID = 6838392826290017725L;
    /**ID*/
    private Long id;
    /**字典类型*/
    private String type;
    /**上级ID*/
    private Integer parentId;
    /**编码*/
    private String code;
    /**名称*/
    private String name;
    /**排序编号*/
    private Integer sort;
    /**显示类型*/
    private Integer displayType;
    /**备注说明*/
    private String description;
    /**HIS对应编码*/
    private String hisId;
    /**备注*/
    private String remarks;
    /**字典分组ID*/
    private Long groupId;

    private DataDictionaryGroup dictGroup;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "SEQ_DICTIONARY")
    @SequenceGenerator(name = "SEQ_DICTIONARY", sequenceName = "DICTIONARY_SEQUENCE", allocationSize=1)
    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

      public Integer getDisplayType() {
        return displayType;
    }

    public void setDisplayType(Integer displayType) {
        this.displayType = displayType;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getHisId() {
        return hisId;
    }

    public void setHisId(String hisId) {
        this.hisId = hisId;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Long getGroupId() {
        return groupId;
    }

    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }

    @ManyToOne
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "groupId", nullable = false, updatable = false, insertable = false)
    public DataDictionaryGroup getDictGroup() {
        return dictGroup;
    }


    public void setDictGroup(DataDictionaryGroup dictGroup) {
        this.dictGroup = dictGroup;
    }

    @Transient
    public String getGroupCode() {
        if (dictGroup != null) {
            return dictGroup.getCode();
        }
        return "";
    }
}
